package com.lxc.domain.register.service;

import org.reactivestreams.Publisher;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author lxc18
 * @date 2024/12/25 15:35
 * @description IMessageServiceImpl
 */
@Service
public class IMessageServiceImpl implements IMessageService{
    @Value("${spring.redis.host}")
    private String host;
    @Value("${spring.redis.port}")
    private Integer port;

    private final RedisTemplate<String, Object> redisMessageTemplate;

    public IMessageServiceImpl(RedisTemplate<String, Object> redisMessageTemplate) {
        this.redisMessageTemplate = redisMessageTemplate;
    }

    @Override
    public Map<String, String> queryRedisConfig() {
        return new HashMap<String, String>() {{
            put("host", host);
            put("port", String.valueOf(port));
        }};

    }

    @Override
    public void pushMessage(String gatewayId, Object message) {
        redisMessageTemplate.convertAndSend(gatewayId, message);
    }
}
